﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;

namespace TimeTrak.BLL
{
    public delegate void TickEventHandler(object sender, ElapsedEventArgs e);

    class TimeManager
    {
        const double TIME_STEP = 15000; //how often to update current time on running tasks
        Timer mainTimer;
        public event TickEventHandler TimerTick;
        
        public TimeManager()
        {
            mainTimer = new Timer(TIME_STEP);
            mainTimer.AutoReset = true;
            mainTimer.Elapsed += new ElapsedEventHandler(mainTimer_Elapsed);


        }

        void mainTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                TimerTick(this, e);
            }
            catch (Exception ex)
            {
                throw new Exception("Error in TimeManager.Elapsed handler!", ex);
            }
        }

        public void Start()
        {
            mainTimer.Start();
        }
        public void Stop()
        {
            mainTimer.Stop();
        }
    }
}
